/*
 * @Author: CodeHare
 * @Date: 2023-10-24 16:48:47
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2023-12-11 16:08:56
 * @Description: 消息中心
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/app_permission/permission_widget.dart';
import 'package:yt_devops/pages/mine/message_center/message_center_controller.dart';
import 'package:yt_devops/resources/resources.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/utils/constants/permission_page_constant.dart';

class MessageCenterPage extends GetView<MessageCenterController> {
  MessageCenterPage({Key? key}) : super(key: key);
  @override
  final controller = Get.put(MessageCenterController());
  final state = Get.find<MessageCenterController>().state;

  Widget _generateList() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        PermissionWidget(
          permissionStringList: const [
            PermissionConstant.mineMessageCenterAdvertiseMessage
          ],
          child: GestureDetector(
            onTap: () => controller.goAdvertiseMessage(),
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 16.w),
              width: double.infinity,
              height: 52,
              clipBehavior: Clip.hardEdge,
              margin: const EdgeInsets.only(left: 16, right: 16),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(8),
                color: Colors.white,),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Expanded(
                    child: Text(
                      ResKey.advertiseMessage.tr,
                      style: TextStyle(
                        color: Colour.mainTextColor,
                        fontSize: 16.sp,
                      ),
                    ),
                  ),
                  controller.hasUnread
                      ? Image.asset(
                          ImageAssets.messageTip,
                          width: 8.w,
                          height: 8,
                        )
                      : Container(),
                  Image.asset(
                    ImageAssets.rightArrow,
                    width: 20.w,
                    height: 20,
                  ),
                ],
              ),
            ),
          ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MessageCenterController>(
      builder: (_) {
        return Scaffold(
          backgroundColor: Colour.backgroundColor,
          appBar: AppBarWidget.defaultAppBar(
            ResKey.messageCenter.tr,
          ),
          body: Container(
            margin: const EdgeInsets.symmetric(
              vertical: 10,
            ),
            child: _generateList(),
          ),
        );
      },
    );
  }
}
